package com.scholarship.modules.backend.controller;

import com.scholarship.common.entity.RetCode;
import com.scholarship.common.entity.RetResponse;
import com.scholarship.common.entity.RetResult;
import com.scholarship.modules.backend.entity.CreateTableInfo;
import com.scholarship.modules.backend.entity.RewardType;
import com.scholarship.modules.backend.exce.CreateTableException;
import com.scholarship.modules.backend.service.CreateTableService;
import com.scholarship.modules.backend.service.RewardTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.List;


/**
 * @author zhz
 * @date 2021/4/12 13:01
 * 备注：和创建数据库相关的Controller
 *      1.选择要创建数据库的名字：reward_type_detail.name
 *      2.输入表名：reward_type_detail.table_name
 *      3.设置属性：中文、英文、类型
 */
@RestController
@Api(tags = {"创建数据库表"})
public class CreateTableController {
    @Autowired
    CreateTableService createTableService;
    @ApiOperation("创建数据库表 @author zhz")
    @PostMapping("/admin/CreateTable")
    public RetResult CreateTable(@RequestBody CreateTableInfo info){
       try{
           createTableService.createTable(info);
           return RetResponse.makeRsp(RetCode.SUCCESS,"成功添加奖学金表格");
       }catch (CreateTableException e){
           return RetResponse.makeRsp(RetCode.FAIL,e.getLocalizedMessage());
       }catch (Exception e){
           return RetResponse.makeRsp(RetCode.INTERNAL_SERVER_ERROR,"服务器内部错误！");
       }
    }
}
